package com.navi.loaddata.loadService.impl.Dcdata.cell2;

import com.navi.loaddata.core.etlException.ETLException;
import com.navi.loaddata.core.mesEntity.MesProductEntity;
import com.navi.loaddata.core.mesEntity.SpcDcdata;
import com.navi.loaddata.core.oracleEntity.cell2.EtlCell2PdsChipV;
import com.navi.loaddata.core.repository.impl.MesRepositoryImpl;
import com.navi.loaddata.core.util.LoggerUtil;
import com.navi.loaddata.core.util.ProcessUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author jay
 */
@Service
public class ProcessDcDataServiceCELL22 {

    @Autowired
    private MesRepositoryImpl daomes;
    private static final Logger logger = LoggerFactory.getLogger(ProcessDcDataServiceCELL22.class);

//    public List<EtlCell2PdsChipV> processDcData(List<SpcDcdata> spcDcdataEntityList,int errorProcessSpcDcdata) throws ETLException {
//        List<EtlCell2PdsChipV> etlCfPdsGlassVList = new ArrayList<>();
//        for(int i=0;i<spcDcdataEntityList.size();i++){
//            EtlCell2PdsChipV etlCfPdsGlassV = new EtlCell2PdsChipV();
//            try {
//                etlCfPdsGlassV = processDcData(spcDcdataEntityList.get(i), errorProcessSpcDcdata);
//                etlCfPdsGlassVList.add(etlCfPdsGlassV);
//            }catch (Exception e){
//                logger.error(LoggerUtil.stackTraceToString(e));
//                throw new ETLException(e.getMessage());
//            }
//        }
//        return etlCfPdsGlassVList;
//    }

    public EtlCell2PdsChipV processDcData(SpcDcdata d, int errorProcessSpcDcdata) throws ETLException {
        EtlCell2PdsChipV etlCfPdsGlassV = new EtlCell2PdsChipV();
        try {



            etlCfPdsGlassV.setStepId(d.getProcessoperationname());
            etlCfPdsGlassV.setSubEquipId(d.getUnitname());
            etlCfPdsGlassV.setChipId(d.getMaterialname());
            etlCfPdsGlassV.setGlassId(d.getMaterialname());
            etlCfPdsGlassV.setChipEndTime(d.getEventtime());
            etlCfPdsGlassV.setProductId(d.getProductspecname());
            etlCfPdsGlassV.setRouteId(d.getProcessflowname());
            etlCfPdsGlassV.setGroupId(d.getLotname());
//            etlCfPdsGlassV.setLotId(d.getLotname());
            etlCfPdsGlassV.setEquipId(d.getMachinename());
            etlCfPdsGlassV.setRunMode(d.getRunmode());
            etlCfPdsGlassV.setRecipeId(d.getRecipename());
            etlCfPdsGlassV.setOperatorId(d.getEventuser());
            etlCfPdsGlassV.setOwnerId(d.getOwnercode());
            etlCfPdsGlassV.setMesLinkKry(d.getMeslinkkey());
            etlCfPdsGlassV.setChipNo(ProcessUtil.processString(d.getMaterialname().substring(d.getMaterialname().length()-2,d.getMaterialname().length())));
            etlCfPdsGlassV.setArrayGlassId(ProcessUtil.processString(d.getMaterialname().substring(0,10)));
            String CfGlassId=daomes.find(MesProductEntity.class,"from MesProductEntity where productname='"+d.getMaterialname()+"'").get(0).getCfproductname();
            etlCfPdsGlassV.setCfGlassId(ProcessUtil.processString(CfGlassId));
        }catch (Exception e){
            logger.error(errorProcessSpcDcdata+":"+e.getMessage());
            logger.error(LoggerUtil.stackTraceToString(e));
            throw new ETLException(errorProcessSpcDcdata+":"+e.getMessage());
        }
//        etlCfPdsGlassV.setTaShift(); todo
        return etlCfPdsGlassV;
    }

}
